package com.we823.cms.repository.service.cms;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.we823.cms.common.web.pageable.PageRequest;
import com.we823.cms.common.web.pageable.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.we823.cms.model.cms.PhotoLink;
import com.we823.cms.repository.dao.cms.PhotoLinkMapper;
import com.we823.cms.repository.service.AbstractBaseService;
import tk.mybatis.mapper.entity.Example;

@Service
@Scope("prototype")
public class PhotoLinkService extends AbstractBaseService<PhotoLink, Integer> {

	private PhotoLinkMapper photoLinkMapper;
	
	@Autowired
	public PhotoLinkService(PhotoLinkMapper photoLinkMapper) {
		super(photoLinkMapper);
		this.photoLinkMapper = photoLinkMapper;
	}

	public List<PhotoLink> findByCategory(String category,Sort sort){
		setSortInfo(sort);
		return this.findByCategory(category);
	}

	public PageInfo<PhotoLink> findByCategory(String category,
											  PageRequest pageRequest) {
		setPageInfo(pageRequest);
		return new PageInfo<>(this.findByCategory(category));
	}

	public List<PhotoLink> findByCategory(String category){
		Example example = new Example(PhotoLink.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("category", category);
		return photoLinkMapper.selectByExample(example);
	}
}
